/**
 * 商品出库明细表js
 */

$(function () {
	initialPage();
});

function initialPage() {
	$(window).resize(function() {
		$('#dataGrid').bootstrapTable('resetView', {height: $(window).height()-56});
	});
}

var vm = new Vue({
	el:'#dpLTE',
	data: {
		keyword: null,
        inProductId: null
	},
	methods : {
		load: function() {
			$('#dataGrid').bootstrapTable('refresh');
		},
		/*save: function() {
			dialogOpen({
				title: '新增出库明细表',
				url: 'base/outbound/details/add.html?_' + $.now(),
				width: '420px',
				height: '350px',
				yes : function(iframeId) {
					top.frames[iframeId].vm.acceptClick();
				},
			});
		},
		edit: function(id) {
            dialogOpen({
                title: '编辑出库明细表',
                url: 'base/outbound/details/edit.html?_' + $.now(),
                width: '420px',
                height: '350px',
                success: function(iframeId){
                    top.frames[iframeId].vm.outBoundDetails.id = id;
                    top.frames[iframeId].vm.setForm();
                },
                yes: function(iframeId){
                    top.frames[iframeId].vm.acceptClick();
                }
            });
        },
        remove: function(batch, id) {
            var ids = [];
            if (batch) {
                var ck = $('#dataGrid').bootstrapTable('getSelections');
                if (!checkedArray(ck)) {
                    return false;
                }
                $.each(ck, function(idx, item){
                    ids[idx] = item.id;
                });
            } else {
                ids.push(id);
            }
            $.RemoveForm({
                url: '../../../outboundDetails/remove?_' + $.now(),
                param: ids,
                success: function(data) {
                    vm.load();
                }
            });
        },*/
        getGrid: function () {
            $('#dataGrid').bootstrapTableEx({
                url: '../../../inOutboundDetails/list?_' + $.now(),
                height: $(window).height()-56,
                queryParams: function(params){
                    params.name = vm.keyword;
                    params.inProductId = vm.inProductId;
                    return params;
                },
                columns: [
                    {
                        field: "num",
                        title : '序号',
                        align: "center",
                        width: 40,
                        formatter: function (value, row, index) {
                            //获取每页显示的数量
                            var pageSize=$('#dataGrid').bootstrapTable('getOptions').pageSize;
                            //获取当前是第几页
                            var pageNumber=$('#dataGrid').bootstrapTable('getOptions').pageNumber;
                            //返回序号，注意index是从0开始的，所以要加上1
                            return pageSize * (pageNumber - 1) + index + 1;
                        }
                    },
                    {field : "outBoundNumber", title : "出库单号", width : "100px"},
                    {field : "outBoundTime", title : "出库时间", width : "200px"},
                    {field : "productName", title : "商品名称", width : "100px"},
                    {field : "outQuantity", title : "出库数量", width : "100px"},
                    {field : "unit", title : "单位", width : "50px"},
                    {field : "outPrice", title : "出库单价", width : "100px",
                        formatter : function (value, row, index) {
                            return value.toFixed(2);
                        }
                    },

                    {field : "outMoney", title : "出库金额", width : "100px",
                        formatter : function (value, row, index) {
                            return value.toFixed(2);
                        }
                    },
                    {field : "profit", title : "当次利润", width : "100px",
                        formatter : function (value, row, index) {
                            return value.toFixed(2);
                        }
                    }
                ]
            })
        }
	}
})